/*
 * Copyright 2010 Christian Schindelhauer, Peter Thiemann, Faisal Aslam, Luminous Fennell and Gidon Ernst.
 * All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 * 
 * This code is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * only, as published by the Free Software Foundation.
 * 
 * This code is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 3 for more details (a copy is
 * included in the LICENSE file that accompanied this code).
 * 
 * You should have received a copy of the GNU General Public License
 * version 3 along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 * 
 * Please contact Faisal Aslam 
 * (aslam AT informatik.uni-freibug.de or studentresearcher AT gmail.com)
 * if you need additional information or have any questions.
 */
package takatuka.tukFormat;

import takatuka.tukFormat.logic.factory.*;
import takatuka.tukFormat.logic.file.*;
import takatuka.classreader.logic.factory.*;
import takatuka.classreader.logic.logAndStats.*;
import takatuka.offlineGC.logic.StartMeOGC;
import takatuka.optimizer.bytecode.branchSetter.logic.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * @author Faisal Aslam
 * @version 1.0
 */
public class StartMeLF extends StartMeOGC {

    private static final LogHolder logHolder = LogHolder.getInstanceOf();
    private static boolean alwaysBigMethods = false;
    public static LFWriter writer = null;
    /**
     * If the JVM is based on a big switch or labels based direct references
     */
    public static boolean generateSwitchNotLables = false;

    protected StartMeLF() {
    }

    public static boolean shouldAlwaysBigMethods() {
        return alwaysBigMethods;
    }

    public static void setAlwaysBigMethods() {
        alwaysBigMethods = true;
    }

    @Override
    public void workAfterWrite() {
    }

    @Override
    public void init(String args[]) throws Exception {
        super.init(args);
        writer = new LFWriter(args[1]);
    }

    @Override
    public void setFactoryFacade() {
        super.setFactoryFacade();
        FactoryPlaceholder.getInstanceOf().setFactory(LFFactoryFacade.getInstanceOf());
    }

    @Override
    public void setOutputWriter(String args[]) throws Exception {
        super.outputWriter = writer;//new LFWriter(args[1]);
    }

    private void vmAutoGenerate() {
        try {
        } catch (Exception d) {
            System.err.println("Exception in vmAutoGenerate ="+d);
            System.exit(1);
        }

    }

    @Override
    public void execute(String args[]) throws Exception {
        super.execute(args);
        //DO not remove me.
        //BranchInstructionsHandler.getInstanceOf().restoreBranchInformation();
        //Miscellaneous.println("Generated <cinit> code....");
        logHolder.addLog("Loading format is generated....");
    }

    public static void main(String args[]) throws Exception {
        (new StartMeLF()).start(args);
    }
}
